/*************************************************
Author: byron
Date: 08/05/2013
Description:
Notes: 
*************************************************/

#ifndef __CSystemNoticeCfg_h__
#define __CSystemNoticeCfg_h__

#include "CActCfg.h"
#include "commclass.h"
#include "CTArray.h"
#include "CTHashObjectMgr.h"

class MsgReqGMPlayer;
class MsgAnsGMPlayer;

class CSystemNoticeCfgData
{
public:
    CSystemNoticeCfgData() 
    {
        Clear();
    }

    void Clear()
    {
        _iID = 0;
        _iInterval = 0;
        _iLastDay = 0;
        _iLastNotice = 0;
        _astSegTime.Clear();
    }

    virtual ~CSystemNoticeCfgData() 
    {
    }

    bool IsValidID() const
    {
        return (_iID > 0 && _iInterval > 0 && _iLastDay >= 0);
    }

    bool IsValidSegTime();

    int GetID() const {return _iID;}
    int GetInterval() const {return _iInterval;}
    int GetLastDay() const {return _iLastDay;}
    int GetLastNotice() const {return _iLastNotice;}

    void SetID(int iVal) {_iID = iVal;}
    void SetInterval(int iVal) {_iInterval = iVal;}
    void SetLastDay(int iVal) {_iLastDay = iVal;}
    void SetLastNotice(int iVal) {_iLastNotice = iVal;}

    bool AddSegTime(CActSegTime& stSegTime)
    {
        if (_astSegTime.Size() < _astSegTime.GetCount())
        {
            if (_astSegTime.AddOneItem(stSegTime) >= 0)
            {
                return true;
            }
        }

        return false;
    }

    int GetSegTimeSize() const {return _astSegTime.Size();}

    CActSegTime& GetSegTime(int iIndex) {return _astSegTime[iIndex];}

    void RefreshSystemNotice();

private:
    int         _iID;   //ID
    int         _iInterval;  //下发间隔(秒为单位)
    int         _iLastDay;   //持续天数(从开服算起)
    int         _iLastNotice;   //上次下发提示时刻

    CTLib::CTArray<CActSegTime, MAX_SYSTEM_NOTICE_SEGMENT_COUNT> _astSegTime;
};

class CSystemNoticeCfg
{
public:
    typedef CTLib::CTHashObjectMgr<int, CSystemNoticeCfgData> T_SYSNOTICE_CFG_HASH;

    CSystemNoticeCfg() 
    {
    }

    virtual ~CSystemNoticeCfg() 
    {
    }

    static int CountSize()
    {
        return T_SYSNOTICE_CFG_HASH::CountSize(MAX_SYSTEM_NOTICE_CONFIG_COUNT);
    }

    int Init(const char* sBuff)
    {
        return _stSysNoticeCfgHash.Init(sBuff, MAX_SYSTEM_NOTICE_CONFIG_COUNT);
    }

    int AddConfig(CSystemNoticeCfgData& stCfgData);

    void RefreshSystemNotice();

    int GMDealSystemNotice(MsgReqGMPlayer& stReq, MsgAnsGMPlayer& stAns);

private:
    T_SYSNOTICE_CFG_HASH _stSysNoticeCfgHash;
};

#endif // __CSystemNoticeCfg_h__

